home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / cool / cool.lha / ice / pisces / rcs / rcsmerge.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-09-04  |  7.1 KB  |  217 lines

  1. /*
  2.  *                       rcsmerge operation
  3.  */
  4. #ifndef lint
  5. static char rcsid[]=
  6. "$Header: /usr4/rock/system/pisces/rcs/RCS/rcsmerge.c,v 1.1 90/05/21 14:49:51 neath Exp $ Purdue CS";
  7. #endif
  8. /*****************************************************************************
  9.  *                       join 2 revisions with respect to a third
  10.  *****************************************************************************
  11.  */
  12.  
  13. /* Copyright (C) 1982, 1988, 1989 Walter Tichy
  14.    Distributed under license by the Free Software Foundation, Inc.
  15.  
  16. This file is part of RCS.
  17.  
  18. RCS is free software; you can redistribute it and/or modify
  19. it under the terms of the GNU General Public License as published by
  20. the Free Software Foundation; either version 1, or (at your option)
  21. any later version.
  22.  
  23. RCS is distributed in the hope that it will be useful,
  24. but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  26. GNU General Public License for more details.
  27.  
  28. You should have received a copy of the GNU General Public License
  29. along with RCS; see the file COPYING.  If not, write to
  30. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  31.  
  32. Report problems and direct all questions to:
  33.  
  34.     rcs-bugs@cs.purdue.edu
  35.  
  36. */
  37.  
  38.  
  39.  
  40. /* $Log:    rcsmerge.c,v $
  41.  * Revision 1.1  90/05/21  14:49:51  neath
  42.  * Initial revision
  43.  * 
  44.  * Revision 4.5  89/05/01  15:13:16  narten
  45.  * changed copyright header to reflect current distribution rules
  46.  * 
  47.  * Revision 4.4  88/11/08  12:00:47  narten
  48.  * changes from  eggert@sm.unisys.com (Paul Eggert)
  49.  * 
  50.  * Revision 4.4  88/08/09  19:13:13  eggert
  51.  * Beware merging into a readonly file.
  52.  * Beware merging a revision to itself (no change).
  53.  * Use execv(), not system(); yield exit status like diff(1)'s.
  54.  * 
  55.  * Revision 4.3  87/10/18  10:38:02  narten
  56.  * Updating version numbers. Changes relative to version 1.1 
  57.  * actually relative to 4.1
  58.  * 
  59.  * Revision 1.3  87/09/24  14:00:31  narten
  60.  * Sources now pass through lint (if you ignore printf/sprintf/fprintf 
  61.  * warnings)
  62.  * 
  63.  * Revision 1.2  87/03/27  14:22:36  jenkins
  64.  * Port to suns
  65.  * 
  66.  * Revision 1.1  84/01/23  14:50:36  kcs
  67.  * Initial revision
  68.  * 
  69.  * Revision 4.1  83/03/28  11:14:57  wft
  70.  * Added handling of default branch.
  71.  * 
  72.  * Revision 3.3  82/12/24  15:29:00  wft
  73.  * Added call to catchsig().
  74.  *
  75.  * Revision 3.2  82/12/10  21:32:02  wft
  76.  * Replaced getdelta() with gettree(); improved error messages.
  77.  *
  78.  * Revision 3.1  82/11/28  19:27:44  wft
  79.  * Initial revision.
  80.  *
  81.  */
  82. #include "rcsbase.h"
  83. #ifndef lint
  84. static char rcsbaseid[] = RCSBASE;
  85. #endif
  86. static char co[] = CO;
  87. static char merge[] = MERGE;
  88.  
  89. extern int  cleanup();              /* cleanup after signals                */
  90. extern char * mktempfile();         /*temporary file name generator         */
  91. extern struct hshentry * genrevs(); /*generate delta numbers                */
  92. extern int  nerror;                 /*counter for errors                    */
  93.  
  94. char *RCSfilename;
  95. char *workfilename;
  96. char * temp1file, * temp2file;
  97.  
  98. main (argc, argv)
  99. int argc; char **argv;
  100. {
  101.         char * cmdusage;
  102.         int  revnums; /* counter for revision numbers given */
  103.         int tostdout;
  104.     int nochange;
  105.         char * rev1, * rev2; /*revision numbers*/
  106.     char commarg[revlength+3];
  107.         char numericrev[revlength];   /* holds expanded revision number     */
  108.         struct hshentry * gendeltas[hshsize];/*stores deltas to be generated*/
  109.         struct hshentry * target;
  110.  
  111.         catchints();
  112.         cmdid = "rcsmerge";
  113.         cmdusage = "command format:\n    rcsmerge -p -rrev1 -rrev2 file\n    rcsmerge -p -rrev1 file";
  114.     revnums=0;tostdout=false;nochange=false;
  115.  
  116.         while (--argc,++argv, argc>=1 && ((*argv)[0] == '-')) {
  117.                 switch ((*argv)[1]) {
  118.                 case 'p':
  119.                         tostdout=true;
  120.                         /* falls into -r */
  121.                 case 'r':
  122.                         if ((*argv)[2]!='\0') {
  123.                             if (revnums==0) {
  124.                                     rev1= *argv+2; revnums=1;
  125.                             } elif (revnums==1) {
  126.                                     rev2= *argv+2; revnums=2;
  127.                             } else {
  128.                                     faterror("too many revision numbers");
  129.                             }
  130.                         } /* do nothing for empty -r or -p */
  131.                         break;
  132.  
  133.                 default:
  134.                         faterror("unknown option: %s\n%s", *argv,cmdusage);
  135.                 };
  136.         } /* end of option processing */
  137.  
  138.         if (argc<1) faterror("No input file\n%s",cmdusage);
  139.         if (revnums<1) faterror("no base revision number given");
  140.  
  141.         /* now handle all filenames */
  142.  
  143.         if (pairfilenames(argc,argv,true,false)==1) {
  144.  
  145.                 if (argc>2 || (argc==2&&argv[1]!=nil))
  146.                         warn("too many arguments");
  147.                 diagnose("RCS file: %s",RCSfilename);
  148.         if (!(access(workfilename,tostdout?4:6)==0))
  149.             nowork();
  150.  
  151.                 if (!trysema(RCSfilename,false)) goto end; /* give up */
  152.  
  153.                 gettree();  /* reads in the delta tree */
  154.  
  155.                 if (Head==nil) faterror("no revisions present");
  156.  
  157.  
  158.                 if (!expandsym(rev1,numericrev)) goto end;
  159.                 if (!(target=genrevs(numericrev, (char *)nil, (char *)nil, (char *)nil,gendeltas))) goto end;
  160.                 rev1=target->num;
  161.                 if (revnums==1)  /*get default for rev2 */
  162.                         rev2=Dbranch!=nil?Dbranch->num:Head->num;
  163.                 if (!expandsym(rev2,numericrev)) goto end;
  164.                 if (!(target=genrevs(numericrev, (char *)nil, (char *)nil, (char *)nil,gendeltas))) goto end;
  165.                 rev2=target->num;
  166.  
  167.         if (strcmp(rev1,rev2) == 0) {
  168.             diagnose("Merging revision %s to itself (no change)",
  169.                 rev1
  170.             );
  171.             nochange = true;
  172.             if (tostdout) {
  173.                 FILE *w = fopen(workfilename,"r");
  174.                 if (w==NULL)
  175.                     nowork();
  176.                 fastcopy(w,stdout);
  177.             }
  178.             goto end;
  179.         }
  180.  
  181.                 temp1file=mktempfile("/tmp/",TMPFILE1);
  182.                 temp2file=mktempfile("/tmp/",TMPFILE2);
  183.  
  184.                 diagnose("retrieving revision %s",rev1);
  185.                 VOID sprintf(commarg,"-p%s",rev1);
  186.                 if (run((char*)nil,temp1file, co,"-q",commarg,RCSfilename,(char*)nil)){
  187.                         faterror("co failed");
  188.                 }
  189.                 diagnose("retrieving revision %s",rev2);
  190.                 VOID sprintf(commarg,"-p%s",rev2);
  191.                 if (run((char*)nil,temp2file, co,"-q",commarg,RCSfilename,(char*)nil)){
  192.                         faterror("co failed");
  193.                 }
  194.                 diagnose("Merging differences between %s and %s into %s%s",
  195.                          rev1, rev2, workfilename,
  196.                          tostdout?"; result to stdout":"");
  197.  
  198.                 if (
  199.               tostdout
  200.             ? run((char*)nil,(char*)nil,merge,"-p",workfilename,temp1file,temp2file,workfilename,rev2,(char*)nil)
  201.             : run((char*)nil,(char*)nil,merge,     workfilename,temp1file,temp2file,workfilename,rev2,(char*)nil)) {
  202.                         faterror("merge failed");
  203.                 }
  204.         }
  205.  
  206. end:
  207.         VOID cleanup();
  208.     exit(2*(nerror!=0) + nochange);
  209.  
  210. }
  211.  
  212.  
  213. nowork()
  214. {
  215.     faterror("Can't open %s",workfilename);
  216. }
  217.